<?php


// SilverStripe Diary Module 0.0.2
// 17.07.2010
// Author:  nivanka@silverstripers.com

class DiaryEvent extends DataObject{
	
	
	static $db = array(
		"Start" => "Date",
		"End" => "Date",
		"Content" => "Text",
		"Title" => "Varchar",
		"StartTime" => "Time",
		"EndTime" => "Time",
		"Location" => "Varchar",
		"EventType" => "Varchar"
	);
	
	static $many_many = array(
      'Diaries' => 'DiaryHolder'
   	);

	function getCMSFields_forPopup(){

		$fields = new FieldSet();
		
		$fields->push(new TextField('Title', 'Title of the event' ));
		$fields->push(new TextField('EventType', 'Event Type'));
		
		$startDateField = new DateField('Start', 'Starting date' );
		$startDateField->setConfig('showcalendar' , true);
		$startDateField->setLocale("en_US");
		$startDateField->setConfig('dateformat', 'dd/MM/YYYY');
		$fields->push($startDateField); 
		
		$endDateField = new DateField('End', 'End date' );
		$endDateField->setConfig('showcalendar' , true);
		$endDateField->setLocale("en_US");
		$endDateField->setConfig('dateformat', 'dd/MM/YYYY');
		$fields->push($endDateField);
		
		$startTime = new TimeField('StartTime', 'Start Time');
		$startTime->setConfig('showdropdown', true);
		$fields->push($startTime);
		
		$endTime = new TimeField('End', 'End Time');
        $endTime->setConfig('showdropdown', true);
		$fields->push($endTime);
		
		$fields->push(new TextField('Location', 'Event Location'));
		$fields->push(new TextAreaField('Content', 'About the event' ));


		return $fields;

	}
	// Delete entry link
	function DeleteLink(){
		$calendar = DataObject::get_one("DiaryHolder");
		return $calendar->Link() . "delete/" . $this->ID;
	}
	
	//Edit entry link
	function EditLink(){
		$calendar = DataObject::get_one("DiaryHolder");
		return $calendar->Link() . "edit/" . $this->ID;
	}
	
	//View Link
	function ViewLink(){
		$calendar = DataObject::get_one("DiaryHolder");
		return $calendar->Link() . "view/" . $this->ID;
	}
	
	//View type Link
	function ViewTypeLink(){
		$calendar = DataObject::get_one("DiaryHolder");
		return $calendar->Link() . "type/" . strtolower($this->EventType);
	}
}

